package net.towee.server.ftp.files;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import net.towee.model.account.AccountGroup;
import net.towee.server.persistence.AttachmentStore;
import net.towee.server.persistence.DiscussionStore;
import net.towee.server.persistence.DocumentStore;

import org.apache.ftpserver.ftplet.FtpFile;

import com.google.common.collect.ImmutableCollection;

/**
 * This file is root of ftp. It consists of GROUP_NODE files.
 * 
 * @author c58
 */
public class RootFtpFile extends AbstractFtpFile {
	private final ImmutableCollection<AccountGroup> groupsList;
	private final DocumentStore docStore;
	private final AttachmentStore attStore;
	private final DiscussionStore discStore;

	public RootFtpFile(ImmutableCollection<AccountGroup> immutableCollection, DocumentStore docStore, AttachmentStore attStore,
			DiscussionStore discStore) {
		super("Groups", true, 0, "", "", FtpFileType.ROOT_NODE, "/");

		this.groupsList = immutableCollection;
		this.docStore = docStore;
		this.attStore = attStore;
		this.discStore = discStore;
	}

	@Override
	public long getLastModified() {
		return 0;
	}

	@Override
	public List<FtpFile> listFiles() {
		List<FtpFile> files = new ArrayList<FtpFile>();
		
		for(AccountGroup g : groupsList) {
			files.add( new TreeNodeFtpFile( null, g, docStore, attStore, discStore ) );
		}
		
		return files;
	}

	@Override
	public OutputStream createOutputStream(long offset) throws IOException {
		return null;
	}

	@Override
	public InputStream createInputStream(long offset) throws IOException {
		return null;
	}

}
